<?php

namespace Modules\Article\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Routing\Controller;
use Modules\Article\Service\TemplateService;

class TemplateController extends Controller
{
    /**
     * @Notes: 模板列表
     * @Interface:          index
     * @param        TemplateService  $templateService
     * @return:             \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
     * @author:             Jokenzhang
     * @Time:               2020/12/23  14:01
     */
    public function index(TemplateService $templateService)
    {
        $templates = $templateService->all();
        return view('article::template.index', compact('templates'));
    }

    /**
     * @Notes:  设置默认模板
     * @Interface:          setDefaultTemplate
     * @param $name
     * @return:             \Illuminate\Http\RedirectResponse
     * @author:             Jokenzhang
     * @Time:               2020/12/23  14:08
     */
    public function setDefaultTemplate($name)
    {
        //存到配置文件中 config.php
        \HDModule::saveConfig(['template' => $name], 'config');
        return back()->with('success', '设置成功');
    }
}
